package com.cms.recursoshumanos.ui;

import com.cms.recursoshumanos.component.base.TittleField;
import com.cms.recursoshumanos.constant.Constant;
import com.cms.recursoshumanos.container.CyclicHFManager;
import com.cms.recursoshumanos.container.JustifiedHorizontalFieldManager;
import com.cms.recursoshumanos.container.SizebleVFManager;

import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.MessageArguments;
import net.rim.blackberry.api.invoke.PhoneArguments;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.CoverageInfo;
import net.rim.device.api.system.WLANInfo;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.NullField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;

public class RecursosHumanosScreen extends MainScreen 
{
	
	public static Bitmap normalButtonBitmap;
    public static Bitmap focusButtonBitmap;
    public static Bitmap activeButtonBitmap;
        
    public static Border normalButtonBorder;
    public static Border focusButtonBorder;
    public static Border activeButtonBorder;
    
    boolean mMenuEnabled = false;
    SizebleVFManager mContentManager = null;
    CyclicHFManager mMenuManager = null;
    
    Screen prevScreen = null;
    
    public Font font_plain_8 = getFont().derive(Font.PLAIN, 8, Ui.UNITS_pt);
    public Font font_bold_8 = getFont().derive(Font.BOLD, 8, Ui.UNITS_pt);
	public Font font_bold_6 = getFont().derive(Font.BOLD, 8, Ui.UNITS_pt);
	public Font font_italic_7 = getFont().derive(Font.ITALIC, 7, Ui.UNITS_pt);
	
	
	//protected static Utileria tool = new Utileria();
    
    public RecursosHumanosScreen( ) 
    {
        this( 0 );
    }
    public void enviar_email(String direccion)
    {
    	Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(MessageArguments.ARG_NEW, 
				direccion, "", ""));
    }
    public void llamar_numero(String number)
	{
		try
		{
			// get phone number - you must write this yourself
			// assume some method here depending on your solution
			int numberInt = Integer.parseInt(number);
			// make the call
			PhoneArguments callArgs = new PhoneArguments(PhoneArguments.ARG_CALL, number);
			Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, callArgs);
		}
		catch(NumberFormatException ex)
		{
			ex.printStackTrace();
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
    public boolean isConected()
	{
		 if(CoverageInfo.isOutOfCoverage())
         {
			 if(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
			 {
				 return true;
			 }
			 else 
			 {
				 return false;
			 }
         }
		 else
		 { 
			 return true; 
		 }             
	}
    public RecursosHumanosScreen( long style ) 
    {
        super( style );
        
        normalButtonBitmap = Bitmap.getBitmapResource("custom_normal.png");
        focusButtonBitmap  = Bitmap.getBitmapResource("custom_focus.png");
        activeButtonBitmap = Bitmap.getBitmapResource("custom_active.png");
        
        
		normalButtonBorder = BorderFactory.createBitmapBorder( new XYEdges( 14, 12, 14, 12 ), normalButtonBitmap );
		focusButtonBorder  = BorderFactory.createBitmapBorder( new XYEdges( 14, 12, 14, 12 ), focusButtonBitmap );
		activeButtonBorder = BorderFactory.createBitmapBorder( new XYEdges( 14, 12, 14, 12 ), activeButtonBitmap );
		
    }
	public void setTitle( String title ) {
		setTitle(title, new NullField());
	}
    public void setTitle( String title, Field button ) {
    	// Aqui se coloca el logo de la empresa que redireccionara a la pagina inicial
    	VerticalFieldManager UpManager = new VerticalFieldManager()
    	{
  		  protected void paintBackground( Graphics g ) 
  		  {
  			  int oldColor = g.getColor();
  		       
  			  try 
  			  {
  				  g.setColor( Constant.COLOR_BACKGROUND_TITLE );
				  g.setBackgroundColor(Constant.COLOR_BACKGROUND);
  				  g.fillRect( 0, getVerticalScroll(), getWidth(), getHeight() );
  			  } 
  			  finally 
  			  {
  				  g.setColor( oldColor );
  				  g.setBackgroundColor(Color.WHITE);
  				  
  			  }
  		    }
      	};

    	
    	TittleField titleLabel = new TittleField( title, 
    													DrawStyle.HCENTER | 
    													DrawStyle.VCENTER |
    													Field.FIELD_HCENTER |
    													Field.FIELD_VCENTER);
    	
		titleLabel.setFont(font_bold_6);
        
		titleLabel.setFont( titleLabel.getFont().derive( Font.PLAIN, titleLabel.getFont().getHeight() + 2 ) );
        titleLabel.setPosition(5);
        titleLabel.setBackgroundColor(Constant.COLOR_BACKGROUND_TITLE);
        titleLabel.setFontColor(Color.WHITE);

        
        JustifiedHorizontalFieldManager jhfm = new JustifiedHorizontalFieldManager(new NullField(), titleLabel, button) { //JustifiedHorizontalFieldManager.USE_ALL_WIDTH
			protected void paint(Graphics graphics) {
	            graphics.setBackgroundColor(Constant.COLOR_BACKGROUND_TITLE);
	            graphics.clear();
	            
	        	super.paint(graphics);
	        };
        };
        
        
        UpManager.add(jhfm); 
        add(UpManager);
    	
    }
    
    protected boolean onSavePrompt() {
		return false;
	}
    
    
    
    
   
    
}

